package com.dubbo.microserviceweb.controller;

import com.dubbo.microserviceweb.error.BussinessException;
import com.dubbo.microserviceweb.error.EmBussinessError;
import com.dubbo.microserviceweb.response.CommonReturnType;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class BaseController {

    //定义内容类型常量
    public static final String CONTENT_TYPE_FORMED = "application/x-www-form-urlencoded";


    //定义exception解决未被controller层吸收的exception
//    @ExceptionHandler(Exception.class)
//    @ResponseStatus(HttpStatus.OK)
//    @ResponseBody
//    public Object handlerException(HttpServletRequest request,Exception ex){
//        Map<String,Object> responseData = new HashMap<>();
//        if (ex instanceof BussinessException){
//            BussinessException bussinessException =(BussinessException) ex;
//            responseData.put("errCode",bussinessException.getErrCode());
//            responseData.put("errMsg",bussinessException.getErrMsg());
//        }else{
//            responseData.put("errCode", EmBussinessError.UNKNOW_ERROR.getErrCode());
//            responseData.put("errMsg",EmBussinessError.UNKNOW_ERROR.getErrMsg());
//        }
//        return CommonReturnType.create(responseData,"fail");
//    }
}
